<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function webSocketTest(url, params = {}) {
            return new Promise((resolve, reject) => {
                const socket = new WebSocket(url);
                socket.onopen = () => {
                    socket.send(JSON.stringify(params));
                }
                socket.onmessage = (event) => {
                    console.log(event.data);

                    resolve(event.data)
                }
            })
        }

        webSocketTest('ws://localhost:3000', { age: 18 }).then(res => {
            console.log(res);
        })
    </script>
</body>

</html>